home *** CD-ROM | disk | FTP | other *** search
/ START Magazine / START VOL 3 NO 6.st / PARTLOOK.ARC / PARTLOOK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-04  |  4.4 KB  |  193 lines

  1. /*
  2.  * Hard disk partition stat program.
  3.  *
  4.  * Dumps misc. stats from the hard disk partition sector:
  5.  *    partition type
  6.  *    partition start
  7.  *    partition length
  8.  *    bootable
  9.  *    active
  10.  *
  11.  *
  12.  * dlm -- October 4, 1988
  13.  *
  14.  */
  15.  
  16. #include <portab.h>
  17. #include <osbind.h>
  18. #include <stdio.h>
  19.  
  20. /* misc defines */
  21. #define TRUE    1
  22. #define FALSE    0
  23.  
  24. /*
  25.  * More external routines.  These are the DMA buss i/o routines
  26.  * that Supra uploaded to the Developers Forum on Compuserve (PCS 57)
  27.  *
  28.  * Dave and I would like to thank Supra for releasing the source
  29.  * code to these routines.
  30.  *
  31.  */
  32. extern nhd_read();
  33. extern nhd_write();
  34. extern nhd_sense();
  35.  
  36. /*
  37.  * structure defining misc. HD params.
  38.  *
  39.  * NOTE: not all hard disk formatting programs write this to the
  40.  *       partition sector, so the values may be zero or bogus.
  41.  */
  42. typedef struct hd_info {
  43.     WORD  cylinders;
  44.     BYTE  heads,
  45.           res1;
  46.     WORD  rwcc,
  47.           wpc;
  48.     BYTE  land,
  49.           seekrate,
  50.           interleave,
  51.           spt;
  52.     LONG  size;
  53. } HDI, *HDI_PTR;
  54.  
  55. /*
  56.  * structure defining a single hard disk partition
  57.  */
  58. typedef struct hd_part {
  59.     LONG  id;    
  60.     LONG  start;
  61.     LONG  size;
  62. } HDP, *HDP_PTR;
  63.  
  64. /*
  65.  * location of info fields in the partition sector
  66.  */
  67. #define PART_BASE    0x1c6    /* start of the 4 standard partitions */
  68. #define STAT_BASE    0x1b6    /* start of the hard disk stat table  */
  69. #define EXT_BASE    0x156    /* start of the 8 extended partitions */
  70.  
  71.  
  72. BYTE  hd_buff[512];    /* our disk i/o buffer            */
  73.  
  74. void
  75. dump_entry(n, i, hdp)
  76. int n, i;
  77. register HDP_PTR hdp;
  78. {
  79.     char type[6];        /* type string */
  80.     char *boot = "";
  81.     char *enable = "";
  82.  
  83.     /* 
  84.      * pull some magic and extract the first 3 chars of the type as
  85.      * a string.
  86.      */
  87.     if (hdp[i].start) {    /* empty? */
  88.         strncpy(type, ((char *)&hdp[i].id)+1, 3);
  89.         type[3] = 0;
  90.         if (hdp[i].id & 0x80000000L)
  91.             boot = "bootable";
  92.         if (hdp[i].id & 0x01000000L)
  93.             enable = "enabled";
  94.     }
  95.     else
  96.         type[0] = 0;
  97.  
  98.     /* number, start, size, type string, enabled/disabled, bootable */
  99.     printf("%2d:\t%-7ld\t%-7ld\t%2ld\t%-5s\t%s\t%s\n",
  100.         n, hdp[i].start, hdp[i].size,hdp[i].size / 2000L,
  101.         type, enable, boot);
  102. }
  103.  
  104. void
  105. dump_hdinfo(device, unit)
  106. int device, unit;
  107. {
  108.     HDI_PTR      hdi;
  109.     HDP_PTR      hdp;
  110.     register int i;
  111.  
  112.     printf("\n\n\nStats for device %d unit %d\n", device, unit);
  113.  
  114.     /*
  115.      * go read the partition sector from the drive.
  116.      * it is sector 0.
  117.      */
  118.  
  119.     /* secnum, count, buffer, dma device, dma lun */
  120.     if (nhd_read(0L, 1, hd_buff, device, unit)) {
  121.         printf("\tUnable to read partition sector!\n\n");
  122.         return;
  123.     }
  124.  
  125.     /*
  126.      * dump the info in the hard disk stat buffer.
  127.      * NOTE: This may be bogus since not all hard disk formatters
  128.      *       set these values.
  129.      * If the values look bogus then don't print anything.
  130.      */
  131.     hdi = (HDI_PTR) (hd_buff + STAT_BASE);
  132.     if (hdi->cylinders && hdi->heads && hdi->size) {
  133.         printf("Hard disk format table:\n");
  134.         printf("\tcylinders = %d\n",  hdi->cylinders);
  135.         printf("\theads     = %d\n",  hdi->heads);
  136.         printf("\tsize      = %ld\n", hdi->size);
  137.     }
  138.  
  139.     /*
  140.      * There are two tables that give the partitions on a drive.
  141.      * The first one, at PART_BASE is the one Atari gave in the 
  142.      * "Hitch Hikers Guide to the BIOS".  There are 4 entries in
  143.      * that table.  The second table is an extension originally
  144.      * added by Supra.  It adds an additional 8 entries, allowing
  145.      * a total of 12 partitions on a drive.
  146.      */
  147.  
  148.     /* print the header for the dump */
  149.     printf("\n\nPartition info:\n #\tstart\tsize\tmeg\ttype\n");
  150.  
  151.     hdp = (HDP_PTR) (hd_buff + PART_BASE);    /* the base 4 partitions */
  152.     for (i = 0; i < 4; i++)
  153.         dump_entry(i + 1, i, hdp);
  154.  
  155.     hdp = (HDP_PTR) (hd_buff + EXT_BASE);    /* the 8 extended partitions */
  156.     for (i = 0; i < 8; i++)
  157.         dump_entry(i + 5, i, hdp);
  158.  
  159. }
  160.  
  161. void
  162. main()
  163. {
  164.     int device, unit;
  165.     char input[80];
  166.  
  167.     setbuf(stdout, NULL);    /* unbuffered output */
  168.     setbuf(stdin, NULL);    /* unbuffered input */
  169.  
  170.     puts("\t\tHard Disk Stat Program");
  171.     puts("\t\tby Dan Moore and Dave Small");
  172.     puts("\t\tCopyright (c) 1988 by Antic Publishing\n\n");
  173.  
  174.     do {
  175.         do {
  176.             printf("Enter SCSI device: ");
  177.             gets(input);
  178.             device = atoi(input);
  179.         } while (device > 7 || device < 0);
  180.  
  181.         do {
  182.             printf("Enter SCSI unit: ");
  183.             gets(input);
  184.             unit = atoi(input);
  185.         } while (unit > 1 || unit < 0);
  186.  
  187.         dump_hdinfo(device, unit);
  188.  
  189.         printf("\nDump another? ");
  190.         gets(input);
  191.     } while (strcmp(input, "no"));
  192. }
  193.